<template>
  <div>
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" :labelWidth="110"></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :selectionType="'single'"
      :onRowSelectChange="selectChangeHandle"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <el-button @click="closeDrawer(2)" type="primary">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getCarList, vehicleConfiguration, getWarehouseList } from '@/api/dealerSale/TransferManager/Transferred/index.js';
export default {
  data() {
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {},
      fetchApi: getCarList,
      selectList: []
    };
  },
  mixins: [dictionary],
  created() {
    this.getList();
  },
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT_CASCADER',
          label: '车型选择',
          fieldName: 'vehicleInfo',
          placeholder: '请选择',
          options: { titles: ['品牌', '车系', '车型', '配置', '选装'] },
          itemList: []
        },
        {
          type: 'SELECT',
          label: '仓库名称',
          fieldName: 'factoryId',
          placeholder: '请选择',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productDesc',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: 'VIN码',
          fieldName: 'vin',
          placeholder: '请输入'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库名称',
          dataIndex: 'factoryName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN码',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '入库日期',
          dataIndex: 'postingDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '库龄(天)',
          dataIndex: 'days',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车龄(天)',
          dataIndex: 'productDate',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否锁定',
          dataIndex: 'isLock',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: p => {
            return <span>{this.createDictText(p.row.isLock, '1004')}</span>;
          }
        },
        {
          title: '实销配车',
          dataIndex: 'matchFlag',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6041'),
          render: p => {
            return <span>{this.createDictText(p.row.matchFlag, '6041')}</span>;
          }
        },
        {
          title: '退车标记',
          dataIndex: 'backSign',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6040'),
          render: p => {
            return <span>{'否'}</span>;
          }
        },
        {
          title: '是否三方车辆',
          dataIndex: 'isTripartite',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          render: p => {
            return <span>{this.createDictText(p.row.isTripartite, '1004')}</span>;
          }
        }
      ];
    },

    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
    },
    async getList() {
      let res = await vehicleConfiguration(0, { isUnlimited: 10041001 });
      this.topFilterList.find(item => item.fieldName === 'vehicleInfo').itemList = res.data;
      let res1 = await getWarehouseList();
      this.topFilterList.find(item => item.fieldName == 'factoryId').itemList = res1.data.list.map(x => ({ text: x.warehouseName, value: x.warehouseId }));
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close');
      } else {
        if (this.selectList.length < 1) {
          this.$notify({
            title: '警告',
            message: '请选择车辆',
            type: 'warning'
          });
          return;
        }
        let arr = this.selectList;
        this.$emit('close', arr[0]);
      }
    },
    selectChangeHandle(val) {
      this.selectList = val;
    }
  }
};
</script>
